<?php
namespace zhtfrontend\modules\cus\components\services;

use common\components\helpers\Fun;
use common\models\datas\AccountRecord;
use common\models\datas\Customer;
use yii\base\Component;

class Capital extends Component
{
    /*
     * 插入消费付款方式
     */
   public static function insertPayMode($data){
       $columns = ['module_id','code','pay_method','money','type'];
       Fun::getSysDb()->createCommand()->batchInsert('{{%consume_pay_mode}}',$columns,$data)->execute();
   }

   /*
    * 会员资金减少
    */
   public static function reduceCapital($data){
         $modelAccountRecord = new AccountRecord();
         $modelAccountRecord->cash = $data['customer_id'];
         $modelAccountRecord->cash = -$data['cash'];
         $modelAccountRecord->site_id = Fun::getSiteId();
         $modelAccountRecord->user_id =\Yii::$app->user->id;
         $modelAccountRecord->order_id =isset($data['order_id'])?$data['order_id']:0;
         $modelAccountRecord->note = isset($data['note'])?$data['note']:'';
         $modelAccountRecord->state = $data['state'];
         $modelAccountRecord->save(false);
   }

   /*
    *  会员资金增加
    */
   public static function increaseCapital($data){
       $modelAccountRecord = new AccountRecord();
       $modelAccountRecord->cash = $data['customer_id'];
       $modelAccountRecord->cash = $data['cash'];
       $modelAccountRecord->site_id = Fun::getSiteId();
       $modelAccountRecord->user_id =\Yii::$app->user->id;
       $modelAccountRecord->order_id =isset($data['order_id'])?$data['order_id']:0;
       $modelAccountRecord->note = isset($data['note'])?$data['note']:'';
       $modelAccountRecord->state = $data['state'];
       $modelAccountRecord->save(false);
   }
}